#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
int cal(const string& s) {
    // int val = 0;
    int ans = 1, cnt = 1;
    map<int, int> mp;
    for (int i = 1; i < s.length(); ++i) {
        if (s[i] == s[i - 1]) {
            ++cnt;
            if (i == s.length() - 1) {
                mp[cnt]++;
                ans = max(ans, cnt);
            }
        } else {
            mp[cnt]++;
            ans = max(ans, cnt);
            cnt = 1;
        }
    }
    if (ans > 5) return mp[ans] * 3;
    return 0;
}
int chk(const string& s) {
    int val = 0;
    for (int i = 1; i < s.length(); ++i) {
        if (s[i - 1] == 'a' && (s[i] == 'e' || s[i] == 'h')) return -4;
    }
    return val;
}
int ins(const string& s) {
    int val = 0;
    map<int, int> mp;
    int ans = 1, cnt = 1;
    for (int i = 1; i < s.length(); ++i) {
        if (s[i] > s[i - 1]) {
            ++cnt;
            if (i == s.length() - 1) {
                ans = max(ans, cnt);
                mp[cnt]++;
            }
        } else {
            mp[cnt]++;
            ans = max(ans, cnt);
            cnt = 1;
        }
    }
    if (ans > 3) return mp[ans] * 5;
    return 0;
}
int main() {
    string s;
    int n, t, k;
    cin >> n >> t >> k;
    rep(_, 1, k) {
        cin >> s;
        int val = 0;
        if (s.front() == 'f') val -= 2;
        if (s.back() == 'a') val -= 1;
        val += cal(s);
        val += chk(s);
        val += ins(s);
        cout << val;
        if (val > t) cout << "!!!";
        cout << '\n';
    }
    return 0;
}